<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    //定义了一个数组，长度为0
    let arr1 = [];
    // let arr2 = new Array(长度);
    //长度为0
    let arr2 = new Array();
    console.log("arr2:" + arr2.length);
    //长度为1
    let arr3 = new Array(4);
    console.log("arr3:" + arr3.length);

    let arr4 = new Array(4, 2, 5);
    console.log("arr4:" + arr4.length);

    //ES6，创建一个只有元素1的数组
    let arr5 = Array.of(1);
    console.log(arr5);
    //索引：>=0
    arr5[3] = "haha";//1和2的索引上就是空值
    console.log(arr5.length);
    console.log(arr5);
    arr5.length = 10;
    console.log(arr5);
    arr5[-1] = "hello";
    console.log(arr5);
    console.log(arr5[-1]);//当成Object来使用
    console.log(arr5.length);
    arr5["a"] = "11";
    console.log(arr5);
    console.log(arr5.a);
    console.log(arr5.length);

    console.log(...arr5);//只列举数组的对应索引位置上的元素，不能列举属性
    console.log(arr5[0], arr5[1]);

    //只能列举正常范围的索引
    for (let i = 0; i < arr5.length; i++) {

    }
    //index就是索引，能够列举非正常索引，空元素不会列举
    for (let index in arr5) {
        console.log(index);
        console.log(arr5[index]);
    }
    //item元素值，只能列举正常范围的索引，空元素不会处理
    for (let item of arr5) {
        console.log(item);
    }

    //forEach(callbackfn: (value: T, index: number, array: T[]) => void, thisArg?: any): void;
    arr5.forEach(function (value, index, array) {
        console.log(value, index);
    });

    let obj = {
        length: 10,
        forEach(callback, array) {
            for (let i = 0; i < array.length; i++) {
                callback(array[i], i, array);
            }
        }
    };
</script>
</body>
</html>